package utils

import (
	"fmt"
	"gopkg.in/ini.v1"
)

var (
	AppMode  string
	HttpPort string
	JwtKey   string

	Db         string
	DbHost     string
	DbPort     string
	DbName     string
	DbUser     string
	DbPassWord string

	AccessKey   string
	SecretKey   string
	Bucket      string
	QiniuServer string

	MailUserName string
	MailAuthCode string
	MailHost     string
	MailPort     string
)

func init() {
	file, err := ini.Load("config/config.ini")
	if err != nil {
		fmt.Println("配置文件加载错误！请检查文件路径", err)
	}
	LoadService(file)
	LoadDatabase(file)
	LoadQiniu(file)
	LoadEmail(file)
}

func LoadService(file *ini.File) {
	AppMode = file.Section("serve").Key("AppMode").MustString("debug")
	HttpPort = file.Section("serve").Key("HttpPort").MustString(":8081")
	JwtKey = file.Section("serve").Key("JwtKey").MustString("adsfcixytqm")
}

func LoadDatabase(file *ini.File) {
	Db = file.Section("serve").Key("Db").MustString("Mysql")
	DbHost = file.Section("serve").Key("DbHost").MustString("localhost")
	DbPort = file.Section("serve").Key("DdPort").MustString("3306")
	DbName = file.Section("serve").Key("DbName").MustString("ginblog")
	DbUser = file.Section("serve").Key("DbUser").MustString("root")
	DbPassWord = file.Section("serve").Key("DbPassWord").MustString("root")
}

func LoadQiniu(file *ini.File) {
	AccessKey = file.Section("qiuniu").Key("AccessKey").MustString("")
	SecretKey = file.Section("qiuniu").Key("SecretKey").MustString("")
	Bucket = file.Section("qiuniu").Key("Bucket").MustString("")
	QiniuServer = file.Section("qiuniu").Key("QiniuServer").MustString("")
}

func LoadEmail(file *ini.File) {
	MailUserName = file.Section("email").Key("MailUserName").MustString("")
	MailAuthCode = file.Section("email").Key("MailAuthCode").MustString("")
	MailHost = file.Section("email").Key("MailHost").MustString("")
	MailPort = file.Section("email").Key("MailPort").MustString("")
}
